# import logging,time,os.path  # 引入logging模块
# # 将信息打印到控制台上
# # 1.创建提个logging 实例化logging
# logger = logging.getLogger()
# # 日志等级开关
# logger.setLevel(logging.INFO)
#
# # 2、创建一个handle ，用于写入日志文件，
# # time.localtime()-->格式化当前时间戳
# # time.time()-->返回当前时间戳
# rq = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
# log_path = os.path.dirname(os.getcwd() + "/Logs/")
# log_path1 = log_path + rq + "/dir/"
# logfile = log_path1
# print(log_path1,logfile)
# fh = logging.FileHandler(logfile,mode="w")
# fh.setLevel(logging.DEBUG)
#
#
# # 3,定义handler 的输出格式
# formate = logging.Formatter('(%asctime)s - %(filename)s:[line:%(lineno)d - %(levelname)s - %(massage)s')
# fh.setFormatter(formate)
#
# # 4.将logger定义到handler里面
# logger.addHandler(fh)
# # 日志
# logger.debug('this is a logger debug message')
# logger.info('this is a logger info message')
# logger.warning('this is a logger warning message')
# logger.error('this is a logger error message')
# logger.critical('this is a logger critical message')

import logging  # 引入logging模块
import os.path
import time
# 第一步，创建一个logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)  # Log等级总开关
# 第二步，创建一个handler，用于写入日志文件
rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
log_path = os.path.dirname(os.getcwd()) + '/Logs/'
log_name = log_path + rq + '.log'
logfile = log_name
fh = logging.FileHandler(logfile, mode='w')
fh.setLevel(logging.DEBUG)  # 输出到file的log等级的开关
# 第三步，定义handler的输出格式
formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
fh.setFormatter(formatter)
# 第四步，将logger添加到handler里面
logger.addHandler(fh)
# 日志
logger.debug('this is a logger debug message')
logger.info('this is a logger info message')
logger.warning('this is a logger warning message')
logger.error('this is a logger error message')
logger.critical('this is a logger critical message')